package pers.bbw.crr.util;

import cn.hutool.json.JSONUtil;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class LoginUtil {
    public static void httpRequest(HttpServletResponse httpServletResponse, AjaxResult ajaxResult, Integer state) throws IOException {
        httpServletResponse.setContentType("application/json;charset=UTF-8");
        ServletOutputStream outputStream = httpServletResponse.getOutputStream();
        if (state != null) {
            httpServletResponse.setStatus(state);
        }
        outputStream.write(JSONUtil.toJsonStr(ajaxResult).getBytes(StandardCharsets.UTF_8));
        outputStream.flush();
        outputStream.close();
    }
}
